package by.siarhei.java.tij.polymorphism.exercises.ex09;

import java.util.Date;
import java.util.Random;

/**
 * @author Siarhei Shchahratsou <s.siarhei@gmail.com>
 * @since 23.03.2014
 */
public abstract class Rodent {
    private static final Random RANDOM = new Random(new Date().getTime());

    public abstract int getWeight();
    public boolean isPredator() {
        return false;
    }

    @Override
    public String toString() {
        return "Rodent";
    }

    public static void main(String[] args) {
        Rodent[] rodents = new Rodent[10];
        for (int i = 0; i < rodents.length; i++) {
            rodents[i] = makeRand();
        }

        for (Rodent rodent : rodents) {
            print(rodent);
        }
    }

    private static void print(Rodent rodent) {
        System.out.println(rodent + "; weight = " + rodent.getWeight() + "; " + (rodent.isPredator()?"predator":"herbivorous"));
    }

    private static Rodent makeRand() {
        switch (RANDOM.nextInt(3)) {
            case 0: return new Mouse();
            case 1: return new Gerbil();
            case 2: return new Hamster();
            default: throw new IllegalStateException("Unknown kind of Rodent");
        }
    }
}

class Mouse extends Rodent {

    @Override
    public int getWeight() {
        return 100;
    }

    @Override
    public String toString() {
        return "Mouse";
    }
}

class Gerbil extends Rodent {

    @Override
    public int getWeight() {
        return 80;
    }

    @Override
    public String toString() {
        return "Gerbil";
    }

    @Override
    public boolean isPredator() {
        return true;
    }
}

class Hamster extends Rodent {

    @Override
    public int getWeight() {
        return 150;
    }

    @Override
    public String toString() {
        return "Hamster";
    }
}